﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LiteStep.Currencies;
using System.Collections.Generic;

namespace LiteStep.Test
{
	[TestClass]
	public class TestCurrency
	{
		[TestMethod]
		public void TestCurrencyTypes()
		{
			var btc1 = new Btc();
			var ltc1 = new Ltc();
			var usd1 = new Usd();

			var btc2 = new Btc();
			var ltc2 = new Ltc();
			var usd2 = new Usd();

			Assert.AreNotEqual(btc1.CurrencyType, ltc1.CurrencyType);
			Assert.AreNotEqual(btc1.CurrencyType, usd1.CurrencyType);

			Assert.AreNotEqual(ltc1.CurrencyType, btc1.CurrencyType);
			Assert.AreNotEqual(ltc1.CurrencyType, usd1.CurrencyType);

			Assert.AreNotEqual(usd1.CurrencyType, btc1.CurrencyType);
			Assert.AreNotEqual(usd1.CurrencyType, ltc1.CurrencyType);

			Assert.AreEqual(btc1.CurrencyType, btc2.CurrencyType);
			Assert.AreEqual(ltc1.CurrencyType, ltc2.CurrencyType);
			Assert.AreEqual(usd1.CurrencyType, usd2.CurrencyType);

			Assert.AreNotEqual(Btc.Type, Ltc.Type);
			Assert.AreNotEqual(Btc.Type, Usd.Type);

			Assert.AreNotEqual(Ltc.Type, Btc.Type);
			Assert.AreNotEqual(Ltc.Type, Usd.Type);

			Assert.AreNotEqual(Usd.Type, Btc.Type);
			Assert.AreNotEqual(Usd.Type, Ltc.Type);

			Assert.AreEqual(Btc.Type, Btc.Type);
			Assert.AreEqual(Ltc.Type, Ltc.Type);
			Assert.AreEqual(Usd.Type, Usd.Type);
		}

		[TestMethod]
		public void TestCurrencyTypesWithDictionary()
		{
			IDictionary<ICurrencyType, IList<ICurrency>> map = new Dictionary<ICurrencyType, IList<ICurrency>>();

			map.Add(Btc.Type, new List<ICurrency>());
			map.Add(Ltc.Type, new List<ICurrency>());
			map.Add(Usd.Type, new List<ICurrency>());

			var btc = new Btc();
			var ltc = new Ltc();
			var usd = new Usd();

			map[btc.CurrencyType].Add(btc);
			map[ltc.CurrencyType].Add(ltc);
			map[usd.CurrencyType].Add(usd);

			Assert.AreEqual(1, map[Btc.Type].Count);
			Assert.AreEqual(1, map[Ltc.Type].Count);
			Assert.AreEqual(1, map[Usd.Type].Count);

			var btcType = new CurrencyType<Btc>();
			var ltcType = new CurrencyType<Ltc>();
			var usdType = new CurrencyType<Usd>();

			Assert.AreSame(btc, map[btcType][0]);
			Assert.AreSame(ltc, map[ltcType][0]);
			Assert.AreSame(usd, map[usdType][0]);
		}

		[TestMethod]
		public void TestCurrencyNames()
		{
			Assert.AreEqual("BTC", typeof(Btc).Name.ToUpper());
			Assert.AreEqual("LTC", typeof(Ltc).Name.ToUpper());
			Assert.AreEqual("USD", typeof(Usd).Name.ToUpper());
		}
	}
}
